# coding: utf-8
# !/usr/bin/env python3
import pandas as pd
from ipywidgets import interact
from bokeh.models.formatters import DatetimeTickFormatter
from bokeh.io import output_notebook, show, push_notebook
from bokeh.models import ColumnDataSource, DataRange1d, Select
from bokeh.plotting import figure
output_notebook()
Note: cleaned_household_power_consumption.csv is not available in GitHub (as it exeeds size of 100 mb, run the first notebook to get this dataframe
df = pd.read_csv("./data/cleaned_household_power_consumption.csv", infer_datetime_format=True,
parse_dates=[0], index_col=["local_time"])
cols = ["global_active_power", "global_reactive_power", "voltage", "global_intensity", "sub_metering_1", "sub_metering_2",
"sub_metering_3", "sub_metering_other"]
TOOLS = 'crosshair,save,pan,box_zoom,reset,wheel_zoom'
plot = figure(title="Explore Time Series Data", x_axis_type="datetime", y_axis_type="linear", plot_height = 400, tools = TOOLS, plot_width = 800)
x = df.index
y = df.global_active_power
p = plot.line(x, y, line_color="blue", line_width = 2)
plot.legend.location = "top_left"
plot.xaxis.axis_label = "Local Time"
plot.yaxis.axis_label = "Value"
plot.xaxis.formatter = DatetimeTickFormatter(seconds="%Y-%d-%m %H:%M:%S", minutes="%Y-%d-%m %H:%M:%S", hours="%Y-%d-%m %H:%M:%S", days="%Y-%d-%m %H:%M:%S")
def update(col):
x = df.index
y = df[col]
p.data_source.data["x"] = x
p.data_source.data["y"] = y
push_notebook()
show(plot, notebook_handle=True)
interact(update, col=cols)